package com.wd.tech.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.wd.tech.R;
import com.wd.tech.bean.PlateLieBiao;

import java.text.SimpleDateFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * date:2020/4/25
 * author:郑惠洋(Dell)
 * function:所有模块列表展示Adapter
 */
public class PlateLieBiaoAdapter extends RecyclerView.Adapter<PlateLieBiaoAdapter.VH> {

    private Context context;
    private List<PlateLieBiao.ResultBean> list;

    public PlateLieBiaoAdapter(Context context, List<PlateLieBiao.ResultBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_plateliebiao, parent, false);
        return new VH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {

        //主题
        holder.tvName.setText(list.get(position).getSummary()+"");
        //标题
        holder.tvJieshao.setText(list.get(position).getTitle()+"");
        //时间
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat();
        holder.tvTime.setText(simpleDateFormat.format(list.get(position).getReleaseTime()));


        //关注
        holder.tvAttention.setText(list.get(position).getWhetherAdvertising()+"");
        //分享
        //holder.tvShear.setText(list.get(position).getWhetherCollection());

        //图片

        Glide.with(context)
                .load(list.get(position).getThumbnail())
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(10)))
                .into(holder.iv);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class VH extends RecyclerView.ViewHolder {

        @BindView(R.id.iv)
        ImageView iv;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_jieshao)
        TextView tvJieshao;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_attention)
        TextView tvAttention;
        @BindView(R.id.tv_shear)
        TextView tvShear;
        public VH(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
